var isWx=false;
wx.miniProgram.getEnv(function(res) {
    if(res.miniprogram){
        //小程序
        isWx=true;
    }
});
function goFistPage(memberId){
    window.location.href="/phone/index?memberId="+memberId;
}
function goMyPage(memberId){
    window.location.href="/phone/my?memberId="+memberId;
}
function goCartPage(memberId){
    window.location.href="/phone/cart?memberId="+memberId;
}
function goAddress(memberId){
    if(isWx){
        wx.miniProgram.navigateTo({url: '/pages/show/show?url=/phone/address&urlParam=memberId*'+memberId})
    }else{
        window.location.href="/phone/address?memberId="+memberId;
    }
}
function goAddressAndType(memberId,orderId,type){
    if(type=="2"){
        window.location.href="/phone/address?memberId="+memberId+"&orderId="+orderId+"&type="+type;
    }else if(type=="3"){
        window.location.href="/phone/address?memberId="+memberId+"&cartJson="+orderId+"&type="+type;
    }

}
function goDetail(memberId){
    window.location.href="/phone/detail?memberId="+memberId;
}
function goDetailOrder(memberId,orderId){
    if(isWx){
        wx.miniProgram.navigateTo({url: '/pages/show/show?url=/phone/detail&urlParam=memberId*'+memberId+'#orderId*'+orderId})
    }else{
        window.location.href="/phone/detail?memberId="+memberId+"&orderId="+orderId;
    }
}

function goActivityPage(brandId,memberId){
    if(isWx){
        wx.miniProgram.navigateTo({url: '/pages/show/show?url=/phone/activity&urlParam=memberId*'+memberId+'#brandId*'+brandId})
    }else{
        window.location.href="/phone/activity?memberId="+memberId+"&brandId="+brandId;
    }

}
function goProductPage(itemId,memberId){
    if(isWx){
        wx.miniProgram.navigateTo({url: '/pages/show/show?url=/phone/product/'+itemId+'&urlParam=memberId*'+memberId})
    }else{
        window.location.href="/phone/product/"+itemId+"?memberId="+memberId;
    }
}
function goAddAddress(memberId){
    if(isWx){
        wx.miniProgram.redirectTo({url: '/pages/show/show?url=/phone/addAddress&urlParam=memberId*'+memberId});
    }else{
        window.location.href="/phone/addAddress?memberId="+memberId;
    }
}

function goAddAddressOne(memberId,selectType,orderId){
    if(isWx){
        wx.miniProgram.redirectTo({url: '/pages/show/show?url=/phone/address&urlParam=memberId*'+memberId+'#type*'+selectType+'#orderId*'+orderId});
    }else{
        if(selectType=="2"){
            window.location.href="/phone/address?memberId="+memberId+"&type="+selectType+"&orderId="+orderId;
        }
    }
}
function goDetailAll(memberId){
    if(isWx){
        wx.miniProgram.navigateTo({url: '/pages/show/show?url=/phone/detailList&urlParam=memberId*'+memberId})
    }else{
        window.location.href="/phone/detailList?memberId="+memberId;
    }
}
function shouHou(memberId){
    if(isWx){
        wx.miniProgram.navigateTo({url: '/pages/show/show?url=/phone/shouHou&urlParam=memberId*'+memberId})
    }else{
        window.location.href="/phone/shouHou?memberId="+memberId
    }
}
function goKeFu(memberId){
    if(isWx){
        wx.miniProgram.navigateTo({url: '/pages/show/show?url=/phone/kefu&urlParam=memberId*'+memberId})
    }else{
        window.location.href="/phone/kefu?memberId="+memberId
    }

}
function goDetailList(memberId,status){
    if(isWx){
        wx.miniProgram.navigateTo({url: '/pages/show/show?url=/phone/detailList&urlParam=memberId*'+memberId+'#status*'+status})
    }else{
        window.location.href="/phone/detailList?memberId="+memberId+"&status="+status;
    }
}
function goAddAddressOrder(orderId,memberId,type){
    window.location.href="/phone/addAddress?memberId="+memberId+"&orderId="+orderId+"&type="+type;
}

function myUser(memberId){
    if(isWx){
        wx.miniProgram.navigateTo({url: '/pages/show/show?url=/phone/myUser&urlParam=memberId*'+memberId})
    }else{
        window.location.href="/phone/myUser?memberId="+memberId;
    }

}
function coupon(memberId){
    if(isWx){
        wx.miniProgram.navigateTo({url: '/pages/show/show?url=/phone/couponList&urlParam=memberId*'+memberId})
    }else{
        window.location.href="/phone/couponList?memberId="+memberId;
    }
}
function tixian(memberId){
    if(isWx){
        wx.miniProgram.navigateTo({url: '/pages/show/show?url=/phone/tixian&urlParam=memberId*'+memberId})
    }else{
        window.location.href="/phone/tixian?memberId="+memberId;
    }
}
function tixianList(memberId){
    if(isWx){
        wx.miniProgram.navigateTo({url: '/pages/show/show?url=/phone/tixianList&urlParam=memberId*'+memberId})
    }else{
        window.location.href="/phone/tixianList?memberId="+memberId;
    }
}
function logList(memberId,type){
    if(type==null||type==""){
        type='9';
    }
    if(isWx){
        wx.miniProgram.navigateTo({url: '/pages/show/show?url=/phone/logList&urlParam=memberId*'+memberId+'#type*'+type})
    }else{
        window.location.href="/phone/logList?memberId="+memberId+"&type="+type;
    }
}

function goAddAddressById(addressId,memberId){
    window.location.href="/phone/addAddress?memberId="+memberId+"&addressId="+addressId;
}

function goAddAddressOrderById(orderId,addressId,memberId,type){
    window.location.href="/phone/addAddress?memberId="+memberId+"&addressId="+addressId+"&orderId="+orderId+"&type="+type;
}

function goDetailAndAddressId(orderId,addressId,memberId,type){
    if(isWx){
        wx.miniProgram.redirectTo({url: '/pages/show/show?url=/phone/detail&urlParam=memberId*'+memberId+'#addressId*'+addressId+'#orderId*'+orderId+'#type*'+type})
    }else{
        if(type=="2"){
            window.location.href="/phone/detail?memberId="+memberId+"&addressId="+addressId+"&orderId="+orderId+"&type="+type;
        }else if(type=="3"){
            //window.location.href="/phone/detail?memberId="+memberId+"&addressId="+addressId+"&orderId="+orderId+"&type="+type;
            window.location.href="/phone/orderDetail?memberId="+memberId+"&cartJson="+orderId+"&addressId="+addressId;
        }
    }
}

function productPutCart(obj,activityId,memberId,itemId,objClass){
    cart(obj);
    $.post("/phone/productPutCart",{
        memberId : memberId,
        activityId : activityId,
        itemId:itemId,
        type:"2",
        buyNum:1
    },function(resultInfo){
        console.log(resultInfo);
        if (resultInfo.code == 0){
            $("."+objClass).html(resultInfo.msg);
        }else{
            $.toast("商品添加购物车失败！");
        }
    },"json");
}

function sharePage(memberId){
    if(isWx){
        wx.miniProgram.navigateTo({url: '/pages/show/show?url=/phone/share&urlParam=memberId*'+memberId})
    }else{
        window.location.href="/phone/share?memberId="+memberId;
    }
}

function share(unionid){
    $.showLoading("正在制作图片中");
    $.ajax({
        type: "POST",
        url: "/phone/acceptSharePicByUnionid/"+unionid,
        success: function(result){
            $.hideLoading();
            if(1==result.returnInfo.state){
                wx.miniProgram.navigateTo({url: '/pages/share/share?url='+result.returnInfo.result+"&params="+result.returnInfo.errorMsg})
            }else{
                $.toast(result.returnInfo.errorMsg, "text");
            }
        },
        error: function(result){
            $.hideLoading();
            $.toast(result.returnInfo.errorMsg, "text");
        }
    });
}

function shareProduct(unionid,itemId,activityId){
    $.showLoading("正在制作图片中");
    $.ajax({
        type: "POST",
        url: "/phone/acceptShareProductByUnionid/"+unionid,
        data: {"itemId":itemId,"activityId":activityId},
        success: function(result){
            $.hideLoading();
            if(1==result.returnInfo.state){
                wx.miniProgram.navigateTo({url: '/pages/share/share?url='+result.returnInfo.result+"&params="+result.returnInfo.errorMsg})
            }else{
                $.toast(result.returnInfo.errorMsg, "text");
            }
        },
        error: function(result){
            $.hideLoading();
            $.toast(result.returnInfo.errorMsg, "text");
        }
    });
}

function shareBrand(unionid,activityId){
    $.showLoading("正在制作图片中");
    $.ajax({
        type: "POST",
        url: "/phone/acceptShareBrandByUnionid/"+unionid,
        data: {"activityId":activityId},
        success: function(result){
            $.hideLoading();
            if(1==result.returnInfo.state){
                wx.miniProgram.navigateTo({url: '/pages/share/share?url='+result.returnInfo.result+"&params="+result.returnInfo.errorMsg})
            }else{
                $.toast(result.returnInfo.errorMsg, "text");
            }
        },
        error: function(result){
            $.hideLoading();
            $.toast(result.returnInfo.errorMsg, "text");
        }
    });
}

//支付
function payWx(money,openid,recordId,id) {
    wxPay(money,openid,recordId,id);
}